<#include "/able/_inc/_head.html"/>
<#include "/able/_inc/_layout.html"/>

<!DOCTYPE HTML>
<!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="ie9" lang="en"><![endif]-->
<!--[if !IE]><!-->
<html lang="${lang}">

<head>
    <@head />
</head>
<body>
<@layout>
<div class="wrap-content" id="container">
<!-- start: PAGE TITLE -->
<section id="page-title" >
    <div class="row">
        <div class="col-sm-8">
            <a href="${ctx_admin}/account" class="bread btn btn-o btn-primary" ><i class="fa fa-reply"></i></a>
            <label>管理员- 添加管理员</label>
        </div>

    </div>
</section>
<!-- end: PAGE TITLE -->
<!-- start: BASIC TABLE -->

<div class="container-fluid container-fullw bg-white">

    <div class="row">
        <div class="col-md-12">
            <!--<h5 class="over-title margin-bottom-15">Basic <span class="text-bold">Table</span></h5>-->
            <!--<p>-->
            <!--For basic styling&mdash;light padding and only horizontal dividers&mdash;add the base class <code>.table</code> to any <code>&lt;table&gt;</code>. It may seem super redundant, but given the widespread use of tables for other plugins like calendars and date pickers, we've opted to isolate our custom table styles.-->
            <!--</p>-->
            <div class="alert alert-info">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
                <div><i class="fa fa-question-circle"></i>操作提示</div>
                <ul>
                    <li>标识“<em>*</em>”的选项为必填项，其余为选填项。</li>
                    <li>上传图片时请注意图片尺寸问题。</li>
                </ul>
            </div>

            <div class="col-lg-2 col-md-12"></div>
            <div class="col-lg-8 col-md-12">
                <form id="form" role="form" class="form-horizontal" method="post" action="${ctx_admin}<#if model?exists>/account/update<#else>/account/add</#if>">

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="roleId">
                            角色：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <select id="roleId" name="roleId" class="form-control required">
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="name">
                            用户名称：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input type="hidden" id="userId" name="userId" value="${model.userId}">
                            <input type="text" id="name" name="name" placeholder="用户名称"  class="form-control required"  value="${model.name}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="nickName">
                            真实名称：
                        </label>
                        <div class="col-sm-7">
                            <input type="text" id="nickName" name="nickName" placeholder="真实名称"  class="form-control "  value="${model.nickName}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="phone">
                            手机号：
                        </label>
                        <div class="col-sm-7">
                            <input type="text" id="phone" name="phone" placeholder="手机号"  class="form-control "  value="${model.phone}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="eMail">
                            邮箱：
                        </label>
                        <div class="col-sm-7">
                            <input type="text" id="eMail" name="eMail" placeholder="邮箱"  class="form-control "  value="${model.eMail}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="avatar">
                            上传头像：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input id="avatar" name="avatar" type="hidden">
                            <span class="btn btn-primary fileinput-button">
                                <i class="fa fa-cloud-upload"></i>
                                <span>上传头像</span>
                                <input id="fileupload" type="file" name="file" multiple>
                            </span>
                            <a href="${model.avatar}" target="_blank" title="" class="preview btn btn-o btn-danger btn-xs">
                                <i class="fa fa-image"></i>
                            </a>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="sex0">
                            性别：<span class="symbol required" aria-required="true"></span>
                        </label>

                        <div class="col-sm-7">
                            <div class="clip-radio radio-primary">
                                <input id="sex0" type="radio" name="sex" value="1" <#if model.sex==1> checked="checked" </#if>>
                                <label for="sex0">
                                    男
                                </label>
                                <input id="sex1" type="radio" name="sex" value="2" <#if model.sex==2> checked="checked" </#if>>
                                <label for="sex1">
                                    女
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="password">
                            密码：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input type="password" id="password" name="password" placeholder="密码"  class="form-control required"  value="${model.password}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="password2">
                            确认密码：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input type="password" id="password2" name="password2" placeholder="密码"  class="form-control required"  value="${model.password2}" >
                        </div>
                    </div>



                    <div class="form-group margin-bottom-0">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button class="btn  btn-primary" type="submit">
                                确定
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-lg-2 col-md-12"></div>
        </div>
    </div>
</div>

    </@layout>
<!-- The main application script -->
<script type="text/javascript" src="/assets/js/account/account-edit.js"></script>
<script type="text/javascript">

    var validateCheckRadio = function (val) {
        $("input[type='radio'], input[type='checkbox']").on('ifChecked', function(event) {
            $(this).parent().closest(".has-error").removeClass("has-error").addClass("has-success").find(".help-block").hide().end().find('.symbol').addClass('ok');
        });
    };
    var FormValidator = function () {
        "use strict";
        // function to initiate Validation Sample 2
        var runValidator2 = function () {
            var form2 = $('#form');
            var errorHandler2 = $('.errorHandler', form2);
            var successHandler2 = $('.successHandler', form2);

            form2.validate({
                errorElement: "span", // contain the error msg in a small tag
                errorClass: 'help-block',
                errorPlacement: function (error, element) { // render error placement for each input type
                    if (element.attr("type") == "radio" || element.attr("type") == "checkbox") { // for chosen elements, need to insert the error after the chosen container
                        error.insertAfter($(element).closest('.form-group').children('div').children().last());
                    }  else {
                        error.insertAfter(element);
                        // for other inputs, just perform default behavior
                    }
                },
                ignore: "",
                rules: {
                },
                messages: {

                },
                invalidHandler: function (event, validator) { //display error alert on form submit
                    successHandler2.hide();
                    errorHandler2.show();
                },
                highlight: function (element) {
                    $(element).closest('.help-block').removeClass('valid');
                    // display OK icon
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                    // add the Bootstrap error class to the control group
                },
                unhighlight: function (element) { // revert the change done by hightlight
                    $(element).closest('.form-group').removeClass('has-error');
                    // set error class to the control group
                },
                success: function (label, element) {
                    label.addClass('help-block valid');
                    // mark the current input as valid and display OK icon
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
                },
                submitHandler: function (form) {
                    successHandler2.show();
                    errorHandler2.hide();
                    $.ajax({
                        type:form.method,
                        url:form.action,
                        async:false, //同步方法，如果用异步的话，flag永远为1
                        dataType:'json',
                        data:$(form).serialize(),
                        success: function(res){
                            if(res.success){
                                layer.msg(res.message, {
                                    icon: 1,
                                    time: 2000, ///2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    location.href = global.adminPath + "/account"
                                });

                            }else{
                                layer.msg(res.message, {icon: 2});
                            }
                        }
                    });
                }
            });

        };
        return {
            //main function to initiate template pages
            init: function () {
                validateCheckRadio();
                runValidator2();
            }
        };
    }();

    jQuery(document).ready(function() {
        FormValidator.init();
    });
</script>